package com.heima.wemedia.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmMaterialDto;
import com.heima.model.wemedia.pojo.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/v1/material")
@Api(value = "自媒体素材管理", description = "自媒体素材管理API", tags = "自媒体素材管理")
public class WmMaterialController {

    @Resource
    private WmMaterialService wmMaterialService;

    @ApiOperation("上传图片素材")
    @PostMapping(path = "/upload_picture")
    public ResponseResult<WmMaterial> uploadPicture(MultipartFile multipartFile) throws IOException {
        WmMaterial wmMaterial = wmMaterialService.uploadPicture(multipartFile);
        return ResponseResult.success(wmMaterial);
    }

    @PostMapping(path = "/list")
    @ApiOperation("自媒体素材列表分页查询")
    public ResponseResult<List<WmMaterial>> list(@RequestBody WmMaterialDto dto) {
        IPage<WmMaterial> page = wmMaterialService.queryList(dto);
        return PageResponseResult.success(page);
    }

}

